<!doctype html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no" />
	<title>首页</title>
	<link rel="stylesheet" type="text/css" href="../c/aui.css" />
	<style>
		body {
			background-color: transparent;
		}
	</style>
</head>

<body tapmode onclick="	_close()">
</body>
<script type="text/javascript" src="../j/api.js"></script>
<script type="text/javascript">
	var adName = 'zyPangolinAd'; //  baiduAd   ttAd 	iflyAd  zyPangolin
	var ad;
	apiready = function() {
			// 判断返回键
			api.addEventListener({
				name: 'keyback'
			}, function(ret, err) {
				console.log('禁止返回上一页');
			});
			// 回到屏幕
			api.addEventListener({
				name: 'viewappear'
			}, function(ret, err) {
				api.setFullScreen({
					fullScreen: true,
					animation: true,
					optNav: true,
				});
			});
			// 离开屏幕
			api.addEventListener({
				name: 'viewdisappear'
			}, function(ret, err) {
				api.setFullScreen({
					fullScreen: false,
					animation: true,
					optNav: true,
				});
			});
			//应用进入后台事件
			api.addEventListener({
				name: 'pause'
			}, function(ret, err) {
				api.setFullScreen({
					fullScreen: false,
					animation: true,
					optNav: true,
				});
			});
			// 应用从后台回到前台事件
			api.addEventListener({
				name: 'resume'
			}, function(ret, err) {
				api.setFullScreen({
					fullScreen: true,
					animation: true,
					optNav: true,
				});
			});
			ad = api.require(adName);
			// 初始化
			if (adName == 'ttAd') {
				var param = {
					appId: '5043672',
					appName: '趣味短视频',
				};
				ad.init(param, function(ret, err) {
					console.log('初始化init:' + JSON.stringify(ret) + JSON.stringify(err));
				});
			} else if (adName == 'zyPangolin') {
				var param = {
					appId: "5043672",
					appName: "趣味短视频",
				};
				ad.init(param);
			}
			switch (api.pageParam['js']) {
				case 'kaiping':
					kaiping();
					break;
				case 'chaping':
					chaping();
					break;
				case 'jili':
					jili();
					break;
				case 'hengfu':
					hengfu();
					break;
				case 'tiepian':
					tiepian();
					break;
				default:
					_alert('函数不存在', function(ret, err) {
						_close();
					})
			}
		}
		// 开屏广告
	function kaiping() {
		console.log(adName)
		var adIdIOS = '6828822';
		var adIdAndroid = '';
		if (adName == 'baiduAd') {
			ad.showSplashAd({
				rect: {
					x: 0,
					y: 0,
					w: api.winWidth,
					h: api.winHeight
				},
				adId: adIdIOS,
				canClick: true,
				// fixedOn: api.frameName,
				fixed: false
			}, function(ret) {
				console.log('kaiping:' + JSON.stringify(ret));
				switch (ret.code) {
					case 1:
						break;
					case 3:
						// _close();
						break;
					case 4:
						_close();
						break;
					default:
						_alert('kaiping错误码：' + ret.code + '请把问题截图后交给客服2', function(ret, err) {
							_close();
						});
				}
			});
		} else if (adName == 'ttAd') {
			ad.splash({
				codeId: '887289813'
			}, function(ret, err) {
				if (ret) {
					console.log('kaiping_ret:' + JSON.stringify(ret));
					switch (ret.data) {
						case 'success':
							break;
						case 'onClosed':
							_close();
							break;
						default:
							console.log('函数不存在');
					}
				} else {
					console.log('kaiping_err:' + JSON.stringify(err));
				}
			})
		} else if (adName == 'iflyAd') {
			ad.addSplashVideoAd({
				adIdIOS: '6B373C848CDD7C37EDF92D092DD14769',
			}, function(ret, err) {
				if (ret) {
					console.log('kaiping_ret:' + JSON.stringify(ret));
					// switch (ret.data) {
					// 	case 'success':
					// 		break;
					// 	case 'onClosed':
					// 		_close();
					// 		break;
					// 	default: sd
					// 		console.log('函数不存在');
					// }
				} else {
					console.log('kaiping_err:' + JSON.stringify(err));
				}
			});
		} else if (adName == 'zyPangolin') {
			var zyPangolin = api.require('zyPangolin');
			var param = {
				setCodeId: "887289813", //代码位
				rect: { //开屏位置 默认0即为全屏 也可自定义
					x: 0,
					y: 0,
					w: 0,
					h: 0
				},
				fixedOn: "",
				fixed: true
			};
			ad.showSplashAd(param, function(ret) {
				console.log('kaiping:' + JSON.stringify(ret));
			});
		}
	}
	// 插屏广告
	function chaping() {
		if (adName == 'baiduAd') {
			ad.showInterstitialAd({
				rect: {
					x: 0,
					y: api.winHeight / 2 - 150,
					w: api.winWidth,
					h: 300
				},
				adId: '6828823',
				type: 'pauseVideo',
				//  fixedOn: api.frameName,
				fixed: false
			}, function(ret) {
				console.log('chaping:' + JSON.stringify(ret));
				switch (ret.code) {
					case 0:
						break;
					case 2:
						break;
					case 3:
						break;
					case 5:
						_close();
						break;
					case 6:
						_close();
						break;
					default:
						_alert('chaping错误码：' + ret.code + '请把问题截图后交给客服2', function(ret, err) {
							_close();
						});
				}
			});
		} else if (adName == 'ttAd') {
			ad.interaction({
				rect: {
					x: 0,
					y: api.winHeight / 2 - 150,
					w: api.winWidth,
					h: 300
				},
				codeId: '943671733',
				//  fixedOn: api.frameName,
				//  fixed: false
			}, function(ret) {
				console.log('chaping:' + JSON.stringify(ret));
				switch (ret.data) {
					case 'onError':
						break;
					default:
						console.log('chaping函数不存在');
				}
			});
		} else if (adName == 'iflyAd') {
			var iflyAd = api.require('iflyAd');
			iflyAd.addInterstitialAd({
				adIdIOS: '33DEA51C05FB7361F5B305DE58786D82',
				rect: {},
			}，function(ret, err) {
				console.log('chaping:' + JSON.stringify(ret)+JSON.stringify(err));
			});
		}
	}
	// 激励广告
	function jili() {
		if (adName == 'baiduAd') {
			ad.showRewardVideo({
				adId: '6828824',
			}, function(ret) {
				console.log('jili:' + JSON.stringify(ret));
				switch (ret.code) {
					case 0:
						break;
					case 1:
						break;
					case 3:
						break;
					case 4:
						_close();
						break;
					case 5:
						_close();
						break;
					case 7:
						break;
					default:
						console.log(jili_code(ret.code));
						_close();
						// _alert('jili错误码：'+jili_code(ret.code)+'请把问题截图后交给客服2',function(ret,err){
						// 	_close();
						// });
				}
			});
		} else if (adName == 'ttAd') {
			var param = {
				codeId: '943671735',
				rName: '金币',
				rAmount: 100,
				userId: '1',
				extra: 'media_extra'
			}
			ad.rewardVideo(param, function(ret, err) {
				console.log('jili:' + JSON.stringify(ret));
			})
		}
	}

	function jili_code(a) {
		switch (a) {
			case 0:
				msg = '缓存成功';
				break;
			case 1:
				msg = '开始播放';
				break;
			case 2:
				msg = '缓存失败';
				break;
			case 3:
				msg = '播放完成';
				break;
			case 4:
				msg = '广告点击';
				break;
			case 5:
				msg = '关闭了广告';
				break;
			case 6:
				msg = '广告展示失败';
				break;
			case 7:
				msg = '激励广告请求成功';
				break;
			case 8:
				msg = '激励广告请求失败';
				break;
			default:
				msg = '未知错误';
		}
		return a + ',' + msg + ',';
	}
	// 横幅广告
	function hengfu() {
		if (adName == 'baiduAd') {
			ad.showAd({
				rect: {
					x: 0,
					y: 0,
					w: 300,
					h: 300
				},
				adId: '6828821',
				fixedOn: api.frameName,
				fixed: true
			}, function(ret) {
				console.log('hengfu_ret:' + JSON.stringify(ret));
				switch (ret.code) {
					case 0:
						break;
					case 1:
						break;
					case 3:
						_close();
						break;
					case 4:
						_close();
						break;
					default:
						_alert('hengfu错误码：' + ret.code + '请把问题截图后交给客服2', function(ret, err) {
							_close();
						});
				}
			});
		}
	}
	// 视频贴片 ios
	function tiepian() {
		if (adName == 'baiduAd') {
			ad.showPrerollAd({
				rect: {
					x: 0,
					y: 0,
					w: 320,
					h: 240
				},
				adId: '6829841',
				fixedOn: api.frameName,
				fixed: true
			}, function(ret) {
				console.log('tiepian_ret:' + JSON.stringify(ret));
				switch (ret.code) {
					case 0:
						break;
					case 1:
						break;
					case 3:
						_close();
						break;
					case 4:
						_close();
						break;
					default:
						_alert('tiepian错误码：' + ret.code + '请把问题截图后交给客服2', function(ret, err) {
							_close();
						});
				}
			});
		}
	}
</script>

</html>
